package com.smcdd.cdb.dbo.cdb_dbo.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.entity.Picture;
import com.smcdd.cdb.dbo.cdb_dbo.service.entity.Site;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Administrator on 2017/6/19 15:30
 * 邮箱：zhanghuaiha@gmail.com
 */

public class SitePopGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<Site.DataBean> mList;
    private LayoutInflater inflater;

    public SitePopGridAdapter(Context context,List<Site.DataBean> list){
        mContext = context;
        mList = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList == null? 0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_site_pop, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.title = (TextView) convertView.findViewById(R.id.item_popup_tv);
            convertView.setTag(viewHolder);
        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }
        viewHolder.title.setText(mList.get(position).getName());
        return convertView;
    }


    class ViewHolder {
        public TextView title;
    }


    public void addData(List<Site.DataBean> list){
        if (mList != null) {
            mList.clear();
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }
}
